/**
 * @author huangmy
 * @text   员工管理
 */

Ext.extend(CQCIS.module, {
    init: function() {
    	// 页面列表
        var listMeta = [{
            id: 'funcId',
            field: 'funcId',
            desc: 'ID',
            hidden: true
        }, {
            field: 'funcType',
            desc: '权限类型',
            width: 100,
            renderer: function(value) {
                var str = "";
                switch (value) {
                    case '1':
                        str = "系统权限";
                        break;
                    case '2':
                        str = "网站权限";
                        break;
                }
                return str;
            }
        }, {
        	field: 'funcName',
        	desc: '权限名称',
        	width: 100
        }, {
            field: 'funcDesc',
            desc: '权限描述',
            width: 100
        }, {
            field: 'funcResoType',
            desc: '权限资源类型',
            width: 100,
            renderer: function(value) {
            	var str = "";
                switch (value) {
                    case '1':
                        str = "URL";
                        break;
                    case '2':
                        str = "控件";
                        break;
                }
                return str;
            }
        }, {
            field: 'state',
            desc: '状态',
            width: 60,
            renderer: function(value) {
                var str = "";
                switch (value) {
                    case '0':
                        str = "无效";
                        break;
                    case '1':
                        str = "有效";
                        break;
                }
                return str;
            }
        }];
        
        // 增加
        var funcMeta = [{
            id: 'funcId',
            name: 'funcId',
            fieldLabel: 'ID',
            xtype: 'hidden'
        }, {
            name: 'funcType',
            fieldLabel: '权限类型',
            xtype: 'hidden'
        }, {
            name: 'funcName',
            fieldLabel: '权限名称',
            xtype: 'hidden'
        }, {
            name: 'funcResoType',
            fieldLabel: '权限资源类型',
            store: [['1', 'URL'], ['2', '控件']],
            triggerAction: 'all',
            mode: 'local',
            allowBlank: false,
            editable: false,
            xtype: 'combo',
            value: 1
        }, {
            name: 'funcDesc',
            fieldLabel: '权限描述'
        }, {
            fieldLabel: '状态',
            name: 'state',
            store: [['1', '有效'], ['0', '无效']],
            triggerAction: 'all',
            mode: 'local',
            allowBlank: false,
            editable: false,
            xtype: 'combo',
            value: 1
        }];
        
        
        var funcWin = new CQCIS.Window({
            id: 'sm_func_teamWin',
            title: '权限信息',
            height: 160,
            items: new CQCIS.form.DWRForm({
                labelWidth: 100,
                dwr: {
                    load: funcDwr.getFunc,
                    save: funcDwr.createFunc,
                    update: funcDwr.updateFunc
                },
                items: funcMeta,
                afterSubmit: function() {
                    grid.refresh();
                }
            })
        });
        
        // 工具栏修改按钮
        var editBtn = new Ext.Toolbar.Button({
            text: '修改权限',
            iconCls: 'btn_modify',
            handler: function() {
                var menu = grid.getSelectedRow();
                if (menu) {
                    funcWin.load(menu.funcId);
                } else {
                    CQCIS.msg('请选择要修改的记录!');
                }
            }
        });
                
        // 员工信息grid
        var grid = new CQCIS.grid.PageGrid({
            id: 'sm_staff_grid',
            firstColumn: 'radio',
            dwr: {
                call: funcDwr.pageFuncs
            },
            metas: listMeta,
            tbar: [editBtn],
            bbar: 'true',
            initload: true
        });
        
        // 定义关联销毁对象数组，避免内存泄漏
        this.main.associatedComp = [funcWin];
        // 定义页面主元素
        this.main.add(grid);
        // 布局更新
        this.main.doLayout();
    }
});
